<html>
  <head>
    <script language="javascript">
	function changeVersion() 
	{
		var sE = null, url;
		if (document.getElementById) 
		{
		    sE = document.getElementById('version');
		} 
		else if (document.all) 
		{
		    sE = document.all['version'];
		}
		if (sE && (url = sE.options[sE.selectedIndex].value)) 
		{
		    //location.href = url;
			top.location.href = url;
		}
	}
	
	<?php
		function add_ending_slash($path)
		{
			$slash_type = (strpos($path, '\\') === 0) ? 'unix' : 'win'; 
		 
			$last_char = substr($path, strlen($path)-1, 1);
		 
			if ($last_char != '/' and $last_char != '\\') 
			{
				// no slash:
				$path .= ($slash_type == 'win') ? '\\' : '/';
			}
		 
			return $path;
		}	
	
	    function GetRootDirectory()
		{
			$fullFileName = $_SERVER["SCRIPT_FILENAME"];
			$dirName = dirname($fullFileName);
			$lastDirName = $dirName;
			while (strpos($dirName, "httpdocs") !== false)
			{
				$lastDirName = $dirName;
				$dirName = realpath($dirName."/../");
			}
			
			return add_ending_slash($lastDirName);
		}
		
		function GetCurrentRelativeDirectory()
		{
		    $rootDirectory = GetRootDirectory();
			$fullFileName = $_SERVER["SCRIPT_FILENAME"];
			
			$relative = str_ireplace($rootDirectory, "", $fullFileName);
			
			return stripslashes(dirname($relative));
		}
	?>
	</script>
  </head>

  <body>
    <div style="float: left">
	    <img src="header_background.jpg" />
	</div>

	<div style="float: right; position: absolute; bottom: 0; right: 0">
	    Documentation version: 
		<select id="version">
		  <option value="/">Newest</option>
		  <?php
			
			$rootDirectory = GetRootDirectory();
			$currentDirectory = GetCurrentRelativeDirectory();
			
			echo $rootDirectory;
			
			$directories = scandir($rootDirectory);
			
			$versions = array();
			foreach ($directories as $dirName)
			{
				$fullDirName = $rootDirectory.$dirName;
			
				if (is_dir($fullDirName) && $dirName != "." && $dirName != "..")
				{
					array_unshift($versions, $dirName);
				}
			}
			
			for ($i = 0; $i < count($versions); $i++)
			{
				$version = $versions[$i];
			
				?>
				<option value="/<?=$version?>/" <?php if ($version == $currentDirectory) echo "selected" ?>><?=$version?></option>
				<?php
			}
		  ?>
		</select>
		<input type="button" value="Go" onclick="changeVersion();" />
	</div>
  </body>
</html>